var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/configComponent/form/index.tsx
var form_exports = {};
__export(form_exports, {
  FormLayout: () => FormLayout
});
module.exports = __toCommonJS(form_exports);
var import_antd = require("antd");
var import_react = require("react");
var import_scroll_into_view_if_needed = __toESM(require("scroll-into-view-if-needed"));
var import_util = require("../../util");
var import_widgets = require("../../widgets");
var import_common = require("../common");
var import_getInitVals = require("../getInitVals");
var import_useColspan = __toESM(require("../useColspan"));
var import_handleStyle = require("./handleStyle");
var import_index = require("./index.less");
var import_listener = require("./listener");
var import_renderLabel = __toESM(require("./renderLabel"));
var import_viewItem = __toESM(require("./viewItem"));
var import_volidRule = require("./volidRule");
var gutter = { xs: 8, sm: 16, md: 24, lg: 32 };
function getObjPath(obj, p = []) {
  const prev = p.length > 0 ? p[p.length - 1] : "";
  const tmpKey = Object.keys(obj)[0];
  const tmpValue = tmpKey ? obj[tmpKey] : "";
  const current = [];
  if ((tmpKey == null ? void 0 : tmpKey.indexOf(",")) > 0) {
    tmpKey.split(",").forEach((k) => {
      current.push(prev ? `${prev}.${k}` : k);
    });
  }
  current.push(prev ? `${prev}.${tmpKey}` : tmpKey);
  if (import_util.iup.isObject(tmpValue) && Object.keys(tmpValue).length > 0) {
    return getObjPath(tmpValue, [...p, ...current]);
  }
  return [...p, ...current];
}
function handleDate(values, itemName, { init = true, emptyValue = "" }) {
  const namePath = import_util.iup.isArray(itemName) ? [...itemName] : [itemName];
  const name = namePath.pop();
  if ((name == null ? void 0 : name.indexOf(",")) > 0) {
    const arr = name.split(",");
    if (init) {
      const v = arr.map((n) => (0, import_common.getObjValue)(values, [...namePath, n]));
      (0, import_common.setObjValue)(values, itemName, v);
    } else {
      const v = (0, import_common.getObjValue)(values, itemName);
      arr.forEach((n, i) => {
        (0, import_common.setObjValue)(values, [...namePath, n], v[i] ?? emptyValue);
      });
    }
    return true;
  }
  return false;
}
function convertValues(initValues, fields) {
  const splitStr = ",";
  const fn = (items) => {
    items.forEach((field) => {
      var _a, _b;
      const item = { ...field, ...field.antProps };
      if (item.xtype === "container") {
        fn(item.children || item.items);
      } else {
        if (item.name && !handleDate(initValues, item.name, { init: true })) {
          const value = (0, import_common.getObjValue)(initValues, item.name);
          const valueType = item.valueType;
          const nameField = item.nameField ?? (((_b = (_a = item.xtype) == null ? void 0 : _a.endsWith) == null ? void 0 : _b.call(_a, "Help")) ? `${item.name}EXName` : "");
          if (nameField && !import_util.iup.isNullOrEmpty(value, "")) {
            const nameFieldValue = (0, import_common.getObjValue)(initValues, nameField);
            const label = nameFieldValue ?? value;
            if (item.multiple || item.xtype === "MultipleHelp") {
              const labelArray = import_util.iup.isArray(label) ? label : import_util.iup.split(label, splitStr);
              const valueArray = import_util.iup.isArray(value) ? value : import_util.iup.split(value, splitStr);
              const valueLabel = valueArray.map((v, i) => {
                return (v == null ? void 0 : v.hasOwnProperty("value")) ? v : {
                  value: import_util.iup.convertData(v, valueType),
                  label: labelArray[i] ?? v
                };
              }).filter(({ label: label2 }) => !import_util.iup.isNullOrEmpty(label2, ""));
              (0, import_common.setObjValue)(initValues, item.name, valueLabel.length ? valueLabel : null);
            } else {
              (0, import_common.setObjValue)(
                initValues,
                item.name,
                value.hasOwnProperty("value") ? value : {
                  value: import_util.iup.convertData(value, valueType),
                  label
                }
              );
            }
          } else {
            (0, import_common.setObjValue)(initValues, item.name, import_util.iup.convertData(value, valueType, item.format));
          }
        }
      }
    });
  };
  fn(fields);
  return initValues;
}
function FormLayoutComp(cmpProps) {
  const [props, children] = (0, import_util.useDevState)({
    type: "form",
    id: cmpProps["id"] || cmpProps["data-cid"] || "form",
    props: cmpProps,
    items: cmpProps.formConf.children,
    itemKey: "name"
  });
  const formConf = (0, import_react.useMemo)(() => ({ ...cmpProps.formConf, children }), [cmpProps.formConf, children]);
  const {
    formSetRef,
    design,
    opt,
    busKey = "id",
    defaultValue: dv,
    value,
    disabled,
    initSc,
    outRef,
    rules,
    style: formStyle,
    formStyle: rowStyle,
    size: formSize,
    compact: formCompact = false,
    className: defaultFormClassName,
    bordered: defaultBordered,
    onLoad,
    fieldProps,
    disabledNotify = false,
    colon: defaultColon
  } = props;
  const computedDeps = (0, import_react.useRef)({
    deps: /* @__PURE__ */ new Set(),
    proxy: null
  });
  const [fields] = (0, import_react.useMemo)(() => {
    computedDeps.current.deps.clear();
    computedDeps.current.proxy = null;
    const fn = (items, pname = "") => {
      return items.map((item) => {
        const tmp = { ...item };
        if (tmp.xtype === "container") {
          tmp.children = fn(tmp.children || tmp.items, tmp.name);
          delete tmp.name;
        } else if (import_util.iup.isString(tmp.name) && pname) {
          tmp.name = [pname, tmp.name];
        }
        return tmp;
      });
    };
    return [fn(formConf.children || [])];
  }, [formConf.children]);
  const isChange = (0, import_react.useRef)(false);
  const defaultValue = (0, import_react.useMemo)(
    () => convertValues((0, import_getInitVals.getInitVals)({ children: fields }, "form", value || dv) || {}, fields),
    [value, dv, fields]
  );
  const initValue = (0, import_react.useMemo)(() => import_util.iup.deepCopy(defaultValue), []);
  const colspan = formConf.colspan ?? props.colspan;
  const labelPosition = formConf.labelPosition ?? (props.labelPosition || "left");
  const formLayout = formConf.layout ?? (props.layout || (labelPosition === "top" ? "vertical" : "horizontal"));
  const cacheItems = (0, import_react.useMemo)(() => ({}), [formConf]);
  const [form] = import_antd.Form.useForm();
  const [dspan, setDspan] = (0, import_react.useState)(0);
  const gDisabled = formConf.disabled ?? disabled;
  const optType = opt || import_util.iup.getQueryValue("opt");
  const labelWidth = formConf.labelWidth || props.labelWidth || import_util.cssVar.formLabelWidth;
  const [m, setM] = (0, import_react.useState)(rules);
  const [u, forceUpdate] = (0, import_react.useState)({});
  const bordered = formConf.bordered ?? defaultBordered;
  const colon = bordered ? false : formConf.colon ?? defaultColon ?? true;
  const isView = formConf.view ?? props.view;
  const formClassName = import_util.iup.classNames("iup-form-wrapper", defaultFormClassName, {
    "iup-compact-form": formCompact,
    "iup-bordered-form": bordered,
    "iup-view-form": isView
  });
  const mergeHandler = (0, import_react.useMemo)(() => (0, import_listener.mergeEventHandler)(), []);
  const handlers = mergeHandler(initSc);
  const containerId = `${props.id || props["data-cid"] || formConf.name || "form"}`;
  const { breakPairs, breakPoints, setBreakPairs } = (0, import_useColspan.default)(containerId, colspan);
  const labelAlign = props.labelAlign || formConf.labelAlign || "right";
  const formSetId = props["cid"];
  (0, import_react.useEffect)(() => {
    onLoad == null ? void 0 : onLoad();
    outRef.current._compIns.getObserver().prevNotify({ ins: outRef.current }, "onLoad").then();
  }, [formConf]);
  (0, import_util.useUpdateEffect)(() => {
    mergeHandler(initSc, true);
    forceUpdate({});
  }, [initSc]);
  (0, import_util.useUpdateEffect)(() => {
    setM(rules);
  }, [rules]);
  const notifyValuesChange = (0, import_util.useDebounce)(
    ({ updateValue, lastValue }) => {
      import_util.iup.getPageObserver().notify(
        {
          key: getObjPath(updateValue),
          containerId: props["cid"] || containerId,
          form: outRef.current,
          instance: (formSetRef == null ? void 0 : formSetRef.current) || outRef.current,
          args: [updateValue, defaultValue, lastValue]
        },
        "onValuesChange"
      );
    },
    { wait: 250 }
  );
  const notifyComputedChange = (0, import_util.useDebounce)(
    ({ updateValue }) => {
      import_util.iup.getPageObserver().notify(
        {
          args: [updateValue, defaultValue],
          key: formSetId,
          containerId: "formset",
          form: outRef.current,
          instance: (formSetRef == null ? void 0 : formSetRef.current) || outRef.current
        },
        "__updateComputedDeps__"
      );
    },
    { wait: 250 }
  );
  const updateComputedDeps = (0, import_util.useRefCallback)((changedValues) => {
    if (computedDeps.current.deps.size > 0) {
      const changedKeys = Object.keys(changedValues);
      const needUpdate = changedKeys.some((k) => computedDeps.current.deps.has(k));
      needUpdate && forceUpdate({});
    }
  });
  const syncValues = (changedValues) => {
    if (changedValues !== defaultValue) {
      import_util.iup.deepMerge(defaultValue, changedValues, ["origin"]);
    }
    if (formSetId) {
      notifyComputedChange({
        params: {
          key: formSetId,
          containerId: "formset",
          form: outRef.current,
          instance: (formSetRef == null ? void 0 : formSetRef.current) || outRef.current
        },
        updateValue: changedValues
      });
    } else {
      updateComputedDeps(changedValues);
    }
  };
  (0, import_util.useSubscribe)(
    "__updateComputedDeps__",
    ({ args }) => {
      updateComputedDeps(args[0] || {});
    },
    [`formset.${formSetId}`]
  );
  (0, import_react.useEffect)(() => {
    syncValues(defaultValue);
    form.setFieldsValue(defaultValue);
  }, [defaultValue]);
  const rewriteFormApi = {
    resetFields() {
      isChange.current = true;
      syncValues(initValue);
      form.resetFields();
    },
    setFieldsValue(values) {
      isChange.current = true;
      syncValues(values);
      form.setFieldsValue(defaultValue);
    },
    setFieldValue(name, value2) {
      rewriteFormApi.setFieldsValue({ [name]: value2 });
    },
    scrollToField(name, options = {}) {
      const node = (0, import_util.getGlobalContainer)().querySelector(`[data-cid="${containerId}_${name}"]`);
      node && (0, import_scroll_into_view_if_needed.default)(node, {
        scrollMode: "if-needed",
        block: "center",
        ...options
      });
    }
  };
  const validData = () => {
    return form.validateFields().then(
      () => true,
      ({ errorFields }) => {
        const namePath = errorFields[0].name.join("_");
        rewriteFormApi.scrollToField(namePath);
        return false;
      }
    );
  };
  (0, import_util.useExtendRef)(outRef, {
    ...form,
    ...rewriteFormApi,
    isChanged: () => isChange.current,
    setModel: setM,
    clear: () => {
      Object.keys(defaultValue).forEach((key) => {
        defaultValue[key] = void 0;
      });
      form.setFieldsValue(defaultValue);
    },
    getFormatValues,
    getValues: (mergeValues = true, undefinedValue = "", includeHiddenItem, labelInValue = false) => beforeSubmit({ mergeValues, undefinedValue, includeHiddenItem: includeHiddenItem ?? mergeValues, labelInValue }),
    changeFormValues: (values = {}) => rewriteFormApi.setFieldsValue(values),
    mergeRules: (newRule) => setM((m2) => (0, import_volidRule.mergeRules)(m2, newRule)),
    mergeHandler: (...args) => {
      mergeHandler(...args);
      forceUpdate({});
    },
    isValid: validData,
    validData,
    validateForm: form.validateFields,
    getItem: (name) => {
      var _a, _b;
      return (_b = (_a = form.getFieldInstance(name)) == null ? void 0 : _a.getApi) == null ? void 0 : _b.call(_a);
    },
    setBreakPairs,
    setHidden: (name, hidden = true) => {
      setConfigByName(name, { hidden });
    },
    setRequired: (name, required = true) => {
      setConfigByName(name, { required });
    },
    getConfig: () => formConf,
    setConfig,
    setConfigByName,
    getDspan: () => dspan,
    focus: () => {
      focusItem(fields);
      function focusItem(items) {
        var _a, _b, _c;
        for (let index = 0; index < items.length; index++) {
          const element = items[index];
          if (Array.isArray(element.children) && focusItem(element.children)) {
            return true;
          }
          if (element.disabled || element.hidden) {
          } else {
            const item = (_b = (_a = form.getFieldInstance(element.name)) == null ? void 0 : _a.getApi) == null ? void 0 : _b.call(_a);
            if (item == null ? void 0 : item.focus) {
              (_c = item == null ? void 0 : item.focus) == null ? void 0 : _c.call(item);
              return true;
            }
          }
        }
        return false;
      }
    },
    subscribe: (0, import_common.getSubscribeFn)(outRef),
    setReadOnly(name = true, disabled2 = true) {
      if (import_util.iup.isBoolean(name)) {
        import_util.iup.fastDp.form.updateProps({ id: containerId, props: { disabled: disabled2 } });
      } else {
        setConfigByName(name, { disabled: disabled2 });
      }
    }
  });
  const convertItem = (0, import_util.useRefCallback)((itm) => {
    const fp = fieldProps == null ? void 0 : fieldProps[itm.name];
    const { computed, encrypted, ...newItem } = fp ? {
      ...itm,
      ...import_util.iup.isFunction(fp) ? fp(itm) : fp
    } : itm;
    if (encrypted) {
      return {
        ...newItem,
        xtype: () => /* @__PURE__ */ React.createElement(import_antd.Input, { value: "*****", disabled: true })
      };
    }
    if (import_util.iup.isFunction(computed)) {
      const formatValue = beforeSubmit({ labelInValue: true });
      if (computedDeps.current.deps.size === 0) {
        const v1 = new Proxy(formatValue, {
          get(t, p) {
            computedDeps.current.deps.add(p);
            return t[p];
          }
        });
        const v2 = new Proxy(defaultValue, {
          get(t, p) {
            computedDeps.current.deps.add(p);
            return t[p];
          }
        });
        computedDeps.current.proxy = { v1, v2 };
      }
      if (computedDeps.current.proxy) {
        import_util.iup.assign(newItem, computed(computedDeps.current.proxy.v1, computedDeps.current.proxy.v2));
      } else {
        import_util.iup.assign(newItem, computed(formatValue, defaultValue));
      }
    }
    return newItem;
  });
  const _renderItem = (0, import_util.useRefCallback)((originItem, index) => {
    var _a, _b;
    const item = convertItem(originItem);
    const key = item.name || item.itemId || index;
    if (item.hidden)
      return "";
    let cellStyle = { paddingLeft: 0, paddingRight: 0 };
    formLayout === "inline" && (cellStyle["with"] = formConf.minWidth || 300);
    let span = getColspan(item.colspan) || 1;
    if (["attachment", "htmleditor"].includes((_b = (_a = item.xtype) == null ? void 0 : _a.toLowerCase) == null ? void 0 : _b.call(_a))) {
      span = 24;
    }
    return /* @__PURE__ */ React.createElement(import_antd.Col, { key, style: cellStyle, "data-id": key, span }, renderFormItem(item, index));
    function renderFormItem(item2, index2) {
      item2 = item2 || {};
      const { instance: Comp } = (0, import_common.getComp)(item2);
      if (Comp === "Group") {
        return /* @__PURE__ */ React.createElement(
          "div",
          {
            className: "iup-group",
            style: { display: item2.hidden ? "none" : "flex" },
            key: `group_${item2.name || item2.itemId || index2}`
          },
          renderGroup(item2, index2)
        );
      } else {
        return renderFI(item2, index2);
      }
    }
    function renderFI(item2, index2) {
      const { instance: Comp, props: defaultProps } = isView ? { instance: import_viewItem.default } : (0, import_common.getComp)(item2);
      const nameKey = import_util.iup.isArray(item2.name) ? item2.name.join(".") : item2.name;
      const listener = (handlers.children || {})[nameKey] || {};
      const disabled2 = item2.disabled ?? gDisabled;
      if (disabled2 && item2.required) {
        item2.onlyRequiredStyle = true;
      }
      const newRules = disabled2 ? {} : { ...m, ...(0, import_volidRule.initRules)({ children: [item2], outRef, disabled: disabled2 }) };
      let rules2 = newRules[nameKey] || [];
      const dp = filterProps(item2);
      disabled2 && (dp["disabled"] = !!disabled2);
      const clientSqlFilter = dp.clientSqlFilter;
      if (import_util.iup.isFunction(clientSqlFilter)) {
        dp.clientSqlFilter = (args) => clientSqlFilter({ ...args, form: outRef.current });
      }
      "getPopupContainer" in dp && (dp["getPopupContainer"] = getPopupContainer);
      const { onChange, ...others } = { ...dp, ...listener };
      bordered && (others.bordered = false);
      if (!item2.hasOwnProperty("extra") && ["InputNumber", "Input"].includes(item2.xtype) && ["percent", "rate"].includes(item2.type)) {
        item2.extra = "%";
      }
      const inline = formLayout === "vertical" && item2.inline;
      const align = inline ? "left" : formLayout === "vertical" ? "left" : labelAlign;
      const getItemProps = () => {
        const p = {
          ...item2.itemProps,
          label: item2.label ? /* @__PURE__ */ React.createElement(
            import_renderLabel.default,
            {
              width: inline || formLayout !== "vertical" ? item2.labelWidth || labelWidth : "100%",
              label: item2.label,
              langKey: item2.langKey || item2.name,
              labelAlign: align
            }
          ) : "",
          labelAlign: align,
          className: `item-checked-customer formItem ${!item2.label && "form-item-nolabel" || ""}${inline ? " vertical-inline" : ""}`,
          key: nameKey || item2.itemId || index2,
          required: item2.required,
          style: item2.style,
          hidden: item2.hidden
        };
        if (!item2.extra) {
          p.rules = item2.hidden ? void 0 : rules2;
          p.name = item2.name;
        }
        if (item2.dependencies) {
          p.dependencies = item2.dependencies;
        }
        return p;
      };
      const getItemCmp = () => {
        return /* @__PURE__ */ React.createElement(Comp, { ...isView ? { "data-item": item2 } : {}, ...others, ...defaultProps });
      };
      return /* @__PURE__ */ React.createElement(import_antd.Form.Item, { ...getItemProps() }, item2.extra ? /* @__PURE__ */ React.createElement("div", { style: { display: "flex", flexDirection: "row", alignItems: "center", gap: 6 } }, /* @__PURE__ */ React.createElement(
        import_antd.Form.Item,
        {
          name: item2.name,
          noStyle: true,
          style: { flex: 1, minWidth: 0 },
          rules: item2.hidden ? void 0 : rules2
        },
        getItemCmp()
      ), item2.extra) : getItemCmp());
    }
    function renderGroup(item2, index2) {
      const items = item2.children || item2.items || [];
      if (item2.customerStyle) {
        return /* @__PURE__ */ React.createElement("div", { style: item2.customerStyle }, items.map((it, idx) => renderFI(convertItem(it), `${index2}-${idx}`)));
      } else {
        const noColToFormStyle = {
          display: "flex",
          width: "100%",
          marginBottom: 0,
          ...item2.style || {}
        };
        return /* @__PURE__ */ React.createElement(
          import_antd.Form.Item,
          {
            key: `group_item_${index2}`,
            label: item2.label ? /* @__PURE__ */ React.createElement(
              import_renderLabel.default,
              {
                width: formLayout !== "vertical" ? item2.labelWidth || labelWidth : "100%",
                label: item2.label,
                langKey: item2.langKey || item2.name,
                labelAlign: formLayout === "vertical" ? "left" : labelAlign
              }
            ) : "",
            className: `item-checked-customer formItem formContainerItem`,
            style: noColToFormStyle,
            required: item2.required
          },
          items.map((it, idx) => renderFormItem(convertItem(it), `${index2}-${idx}`))
        );
      }
    }
  });
  const _renderForm = (0, import_react.useMemo)(() => {
    if (!dspan) {
      return [];
    }
    computedDeps.current.proxy = null;
    return fields.map(_renderItem);
  }, [fields, formConf, m, dspan, gDisabled, formLayout, u]);
  const fstyle = (0, import_react.useMemo)(() => (0, import_handleStyle.getFormStyle)(formConf, rowStyle), [formConf, rowStyle]);
  const hasBorderStyle = bordered || formConf.bordered ? "border-form" : "";
  const className = (0, import_react.useMemo)(() => import_util.iup.classNames("iup-form", formLayout, hasBorderStyle), [design]);
  const formHandler = { ...handlers };
  delete formHandler.children;
  const getDspan = (0, import_util.useRefCallback)(({ width }) => {
    let index = breakPoints.findIndex((item) => {
      return item > width;
    });
    index = index === -1 ? breakPoints.length - 1 : index;
    const defaultSpan = 24 / breakPairs[breakPoints[index]];
    if (dspan !== defaultSpan) {
      setDspan(defaultSpan || 4);
    }
  });
  async function dealPropsChange(changedValues, allValues, oldValues) {
    const changedEvent = props.onValuesChange || handlers["onValuesChange"];
    const res = await (changedEvent == null ? void 0 : changedEvent(changedValues, allValues));
    if (res === false) {
      rewriteFormApi.setFieldsValue(oldValues);
    } else if (import_util.iup.isObject(res)) {
      syncValues(res);
      if (res !== changedValues) {
        rewriteFormApi.setFieldsValue(defaultValue);
      }
    }
    return res !== false;
  }
  function handleValuesChange(updateValue, allValues) {
    const oldValues = import_util.iup.deepCopy(defaultValue);
    isChange.current = true;
    const paths = getObjPath(updateValue);
    if (paths.length >= 3 && paths[paths.length - 1].indexOf(",") > 0) {
      const v = (0, import_common.getObjValue)(updateValue, paths[paths.length - 1]) || [];
      (0, import_common.setObjValue)(updateValue, paths[paths.length - 3], v[0]);
      (0, import_common.setObjValue)(updateValue, paths[paths.length - 2], v[1]);
    }
    syncValues(updateValue);
    dealPropsChange(updateValue, allValues, oldValues).then((success) => {
      var _a, _b, _c;
      const listener = handlers.children || {};
      Object.keys(updateValue).forEach((key) => {
        var _a2;
        const dp = filterProps(getFormItem(key) || {});
        const onChange = dp.onChange || ((_a2 = listener[key]) == null ? void 0 : _a2.onChange);
        if (onChange && updateValue[key] !== oldValues[key]) {
          onChange(updateValue[key], oldValues[key]);
        }
      });
      if (success && !disabledNotify) {
        (_b = (_a = outRef.current).innerNotify) == null ? void 0 : _b.call(_a, [updateValue, defaultValue], "onValuesChange");
        (_c = formSetRef == null ? void 0 : formSetRef.current) == null ? void 0 : _c.innerNotify([updateValue, defaultValue], "onValuesChange");
        notifyValuesChange({ updateValue, lastValue: oldValues });
      }
    });
  }
  return /* @__PURE__ */ React.createElement("div", { id: `${containerId}_ctx`, style: { position: "relative" } }, /* @__PURE__ */ React.createElement(import_widgets.AutoResize, { onResize: getDspan }, /* @__PURE__ */ React.createElement(
    import_antd.Form,
    {
      name: containerId,
      ...handlers,
      scrollToFirstError: true,
      onValuesChange: handleValuesChange,
      form,
      size: formSize,
      style: formStyle,
      layout: formLayout,
      className: formClassName,
      colon
    },
    /* @__PURE__ */ React.createElement(import_antd.Row, { className, style: fstyle, gutter }, _renderForm)
  )));
  function getFormatValues(initValues = {}) {
    const id = busKey || "id";
    const data = { ...initValues, ...beforeSubmit() };
    const opt2 = optType || ((data == null ? void 0 : data[id]) ? "modifiedRow" : "newRow");
    return (0, import_common.fomatValues)(formConf.name, "form", opt2, id, data)()[formConf.name];
  }
  function beforeSubmit({
    mergeValues = true,
    undefinedValue = "",
    includeHiddenItem = true,
    labelInValue = false
  } = {}) {
    let initValues = form.getFieldsValue();
    if (mergeValues) {
      initValues = { ...defaultValue, ...initValues };
    }
    const fn = (items) => {
      items.forEach((field) => {
        const item = { ...field, ...field.antProps };
        const originValue = (0, import_common.getObjValue)(initValues, item.name);
        if (item.name) {
          if (field.xtype === "container") {
            fn(field.children || field.items);
          } else {
            if (item.hidden && !includeHiddenItem || item.encrypted) {
              import_util.iup.deleteObjKey(initValues, item.name);
            } else {
              const nameField = item.nameField;
              const emptyValue = item.emptyValue ?? undefinedValue;
              if (Array.isArray(originValue)) {
                if (handleDate(initValues, item.name, { init: false, emptyValue })) {
                } else if (originValue.length > 0 && (0, import_common.isValueLabel)(originValue[0])) {
                  (0, import_common.setObjValue)(initValues, item.name, originValue.map((item2) => item2.value).join());
                  nameField && (0, import_common.setObjValue)(initValues, nameField, originValue.map((item2) => item2.label).join());
                } else if (originValue.length === 0) {
                  (0, import_common.setObjValue)(initValues, item.name, emptyValue);
                  nameField && (0, import_common.setObjValue)(initValues, nameField, "");
                } else if (!import_util.iup.isObject(originValue[0])) {
                  (0, import_common.setObjValue)(initValues, item.name, originValue.join());
                }
              } else if ((0, import_common.isValueLabel)(originValue)) {
                (0, import_common.setObjValue)(initValues, item.name, originValue.value);
                nameField && (0, import_common.setObjValue)(initValues, nameField, originValue.label);
              }
              if ((0, import_common.getObjValue)(initValues, item.name) === void 0) {
                (0, import_common.setObjValue)(initValues, item.name, emptyValue);
              }
            }
          }
        }
      });
    };
    if (labelInValue) {
      (0, import_common.convertHelpValues)(initValues);
    }
    fn(fields);
    return initValues;
  }
  function getPopupContainer() {
    return props.getPopupContainer ? props.getPopupContainer() : document.getElementById(`${containerId}_ctx`);
  }
  function getColspan(itemColspan) {
    if (itemColspan === void 0 || itemColspan === null) {
      return dspan;
    }
    const cs = itemColspan * dspan;
    return cs > 24 ? 24 : Math.round(cs);
  }
  function getFormItem(key, formItems) {
    if (cacheItems[key])
      return cacheItems[key];
    formItems = formItems || fields;
    for (let i = 0; i < formItems.length; i++) {
      const item = formItems[i];
      if (item.name === key) {
        cacheItems[key] = item;
        return item;
      }
      const items = item.children || item.items || [];
      if (items.length) {
        const tmp = getFormItem(key, items);
        if (tmp) {
          return tmp;
        }
      }
    }
  }
  function setConfig(config) {
    const prevConfig = [...formConf.children];
    if (import_util.iup.isFunction(config)) {
      const newConfig = config(prevConfig);
      newConfig && import_util.iup.fastDp.form.setItems({ id: containerId, items: newConfig });
    } else {
      let isUpdated = false;
      Object.keys(config).forEach((name) => {
        const item = prevConfig.find((item2) => {
          const itemName = import_util.iup.isArray(item2.name) ? item2.name.join(".") : item2.name;
          return itemName === name;
        });
        if (item) {
          Object.assign(item, config[name]);
          isUpdated = true;
        }
      });
      isUpdated && import_util.iup.fastDp.form.setItems({ id: containerId, items: prevConfig });
    }
  }
  function setConfigByName(name, config) {
    const keys = import_util.iup.isArray(name) ? name : [name];
    setConfig(
      keys.reduce((p, c) => {
        p[c] = config;
        return p;
      }, {})
    );
  }
}
var common_props = /* @__PURE__ */ new Set(["name", "label", "defaultValue", "required", "disabled", "colspan", "langKey"]);
function filterProps(item) {
  let dp = Object.keys(item).reduce((acc, key) => {
    if (!common_props.has(key)) {
      acc[key] = item[key];
    }
    return acc;
  }, {});
  delete dp.itemProps;
  delete dp.inline;
  delete dp.style;
  delete dp.nameField;
  delete dp.extra;
  delete dp.dependencies;
  dp = { ...dp, ...dp.antProps };
  delete dp["antProps"];
  delete dp.customRule;
  delete dp.onlyRequiredStyle;
  delete dp.rules;
  delete dp.defaultValue;
  delete dp.valueType;
  delete dp.emptyValue;
  delete dp.xtype;
  delete dp.labelWidth;
  if (!dp.maxLength) {
    delete dp.maxLength;
  }
  return dp;
}
var InnerFormLayout = (0, import_util.compHoc)((0, import_common.LayConfWrap)(FormLayoutComp), "Form");
var FormLayout = InnerFormLayout;
FormLayout.AntForm = import_antd.Form;
(0, import_util.registerComponent)({ Form: InnerFormLayout });
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FormLayout
});
